package client.comm.baoding.adapter

import android.content.Context
import android.content.Intent
import android.os.Parcelable
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.LinearLayout
import androidx.core.content.ContentProviderCompat.requireContext
import androidx.databinding.DataBindingUtil
import androidx.paging.LoadState
import androidx.paging.LoadStateAdapter
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import client.comm.baoding.R
import client.comm.baoding.api.bean.GoodsIndex
import client.comm.baoding.databinding.*
import client.comm.baoding.ui.PaiduiActivity
import client.comm.baoding.ui.TabOne2Activity
import client.comm.baoding.ui.vm.PaiduiViewModel
import client.comm.baoding.widget.HorizontalPageLayoutManager
import client.comm.baoding.widget.PagingScrollHelper
import client.comm.commlib.base.PagingViewHoder
import client.comm.commlib.base.SyBannerAdapter
import com.bumptech.glide.RequestManager
import com.bumptech.glide.request.RequestOptions
import com.youth.banner.indicator.CircleIndicator
import client.comm.commlib.getScreenWidth

class PaiduiHeaderAdapter(val vm: PaiduiViewModel, val context: PaiduiActivity) :
    LoadStateAdapter<PagingViewHoder>() {


    override fun onCreateViewHolder(parent: ViewGroup, loadState: LoadState): PagingViewHoder {
        return PagingViewHoder(
            DataBindingUtil.inflate(
                LayoutInflater.from(parent.context),
                R.layout.layout_paiduiheader,
                parent,
                false
            )
        ).apply {
            val itemBinding = this.binding as LayoutPaiduiheaderBinding

        }
    }

    override fun onBindViewHolder(holder: PagingViewHoder, loadState: LoadState) {
        val binding = holder.binding as LayoutPaiduiheaderBinding
        binding.event = this
        binding.vm = vm

        binding.zfze = context.intent.getStringExtra("totalPrice")
        binding.syzl = context.intent.getStringExtra("nowMoney")
        binding.zsze = context.intent.getStringExtra("sendMoney")
    }

    var txCli: (() -> Unit)? = null

    fun tx() {
        txCli?.invoke()
    }

    override fun onViewAttachedToWindow(holder: PagingViewHoder) {
        super.onViewAttachedToWindow(holder)
        val lp: ViewGroup.LayoutParams = holder.itemView.getLayoutParams()
        if (lp != null && lp is StaggeredGridLayoutManager.LayoutParams
        ) {
            lp.isFullSpan = true
        }
    }

    // true显示无论什么状态都显示
    override fun displayLoadStateAsItem(loadState: LoadState): Boolean {
        return super.displayLoadStateAsItem(loadState) || (loadState.endOfPaginationReached)
//        return loadState is LoadState.Loading || loadState is LoadState.Error || loadState is LoadState.NotLoading
    }

}